﻿@model IEnumerable<MobileSales.Model.Documents.Document>


@{
    View.Title = Strings.Documents;
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>@Strings.Documents</h2>

<p>
    @Html.ActionLink(Strings.CreateNew, "Index", "Orders", null, new { @class = "icon-button add-icon" })
</p>

<script type="text/javascript">
    function pay(documentId) {
        $("#documentId").val(documentId);
        $("#payForm").submit();
    }
</script>

@using (Html.BeginForm("Pay", "Documents", FormMethod.Post, new { id = "payForm" }))
{
    @Html.Hidden("documentId", 0)
}

<table class="datatable">
    <thead>
    <tr>
        <th style="width:190px"></th>
        <th>
            @ModelStrings.DocumentNo
        </th>
        <th>
            @ModelStrings.CreationDate
        </th>
        <th>
            @ModelStrings.PaymentDate
        </th>
        <th>
            @ModelStrings.Client
        </th>
        <th>
            @ModelStrings.IsPaid
        </th>
    </tr>
    </thead>
    <tbody>
@foreach (var item in Model)
{
    <tr>
        <td>
            @Html.ActionLink(Strings.Details, "Details", new { id = item.Id }, new { @class = "icon-button details-icon" }) |
            @Html.ActionLink(Strings.Delete, "Delete", new { id = item.Id }, new { @class = "icon-button delete-icon" })
        </td>
        <td>
            @item.DocumentNo
        </td>
        <td>
            @String.Format("{0:g}", item.CreationDate)
        </td>
        <td>
            @String.Format("{0:g}", item.PaymentDate)
        </td>
        <td>
            @item.ClientName<br />
            @item.ClientName2<br />
            @item.ClientStreet<br />
            @item.ClientZipcode, @item.ClientCity<br />
            @ModelStrings.Nip: @item.ClientNip
        </td>
        <td>
            @(item.IsPaid ? Strings.Yes : Strings.No)
            @if (!item.IsPaid)
            {
                <br /><a href="#" onclick="pay(@item.Id)">@Strings.PayNow</a>
            }
        </td>
    </tr>
}
</tbody>
</table>

